//https://leetcode.cn/problems/daily-temperatures/submissions/500597129/?envType=study-plan-v2&envId=top-100-liked
//其实就是求你最近的比你大的值的位置；

#include <vector>
#include <stack>
#include <list>
#include <map>
#include <string>
#include <unordered_map>

using namespace std;

class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        //求离你最近的最大值；
        std::vector<int> res(temperatures.size(),0);
        if(temperatures.empty()) return res;
        std::stack<std::list<int>> stack;
        for(size_t i=0;i<temperatures.size();++i){
            while(!stack.empty() && temperatures[stack.top().back()]< temperatures[i]){
                std::list<int> popIs=stack.top();
                stack.pop();
                for(int popi:popIs){
                    res[popi]=i-popi;
                }
            }
            if(!stack.empty()&& temperatures[stack.top().back()] == temperatures[i]) {
                stack.top().push_back(i);
            }else{
                std::list<int> list = {(int)i};
                stack.push(list);
            }
        }
        while(!stack.empty()){
            list<int> popIs=stack.top();
            stack.pop();
            for(int popi:popIs) {
                res[popi]=0;
            }
        }
        return res;
    }
};